﻿PRINT '---------------------------------------'
PRINT 'Starting execution of InstallCore.SQL'
PRINT '---------------------------------------'
GO

USE [{0}]
GO

/****** Object:  Table [dbo].[ws_Accounts]    Script Date: 06/30/2011 13:49:53 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[ws_Accounts](
	[AccountId] [uniqueidentifier] NOT NULL,
	[AccountName] [nvarchar](255) NOT NULL,
	[PrimaryUser] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_ws_Accounts] PRIMARY KEY CLUSTERED 
(
	[AccountId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[ws_Accounts] ADD  CONSTRAINT [DF_ws_Accounts_AccountID]  DEFAULT (newid()) FOR [AccountId]
GO

/****** Object:  Table [dbo].[ws_WebsiteAllowances]    Script Date: 06/30/2011 13:53:08 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[ws_WebsiteAllowances](
	[PurchaseId] [uniqueidentifier] NOT NULL,
	[AccountId] [uniqueidentifier] NOT NULL,
	[WebsitesAllowed] [int] NOT NULL,
 CONSTRAINT [PK_ws_WebsiteAllowances] PRIMARY KEY CLUSTERED 
(
	[PurchaseId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[ws_WebsiteAllowances]  WITH CHECK ADD  CONSTRAINT [FK_ws_WebsiteAllowances_ws_Accounts] FOREIGN KEY([AccountId])
REFERENCES [dbo].[ws_Accounts] ([AccountId])
GO

ALTER TABLE [dbo].[ws_WebsiteAllowances] CHECK CONSTRAINT [FK_ws_WebsiteAllowances_ws_Accounts]
GO

ALTER TABLE [dbo].[ws_WebsiteAllowances] ADD  CONSTRAINT [DF_ws_WebsiteAllowances_PurchaseId]  DEFAULT (newid()) FOR [PurchaseId]
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[ws_Websites](
	[WebsiteId] [uniqueidentifier] NOT NULL,
	[ApplicationId] [uniqueidentifier] NULL,
	[AccountId] [uniqueidentifier] NOT NULL,
	[WebsiteName] [varchar](255) NOT NULL,
	[SystemSubDomain] [varchar](50) NOT NULL,
	[Theme] [uniqueidentifier] NOT NULL,
	[FrontPage] [int] NOT NULL,
 CONSTRAINT [PK_ws_Websites] PRIMARY KEY CLUSTERED 
(
	[WebsiteId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[ws_Websites]  WITH CHECK ADD  CONSTRAINT [FK_ws_Websites_aspnet_Applications] FOREIGN KEY([ApplicationId])
REFERENCES [dbo].[aspnet_Applications] ([ApplicationId])
GO

ALTER TABLE [dbo].[ws_Websites] CHECK CONSTRAINT [FK_ws_Websites_aspnet_Applications]
GO

ALTER TABLE [dbo].[ws_Websites]  WITH CHECK ADD  CONSTRAINT [FK_ws_Websites_ws_Accounts] FOREIGN KEY([AccountId])
REFERENCES [dbo].[ws_Accounts] ([AccountId])
ON DELETE CASCADE
GO

ALTER TABLE [dbo].[ws_Websites] CHECK CONSTRAINT [FK_ws_Websites_ws_Accounts]
GO

ALTER TABLE [dbo].[ws_Websites] ADD  CONSTRAINT [DF_ws_Websites_WebsiteID]  DEFAULT (newid()) FOR [WebsiteId]
GO

ALTER TABLE [dbo].[ws_Websites] ADD  CONSTRAINT [DF_ws_Websites_FrontPage]  DEFAULT ((0)) FOR [FrontPage]
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[ws_DomainNames](
	[WebsiteId] [uniqueidentifier] NOT NULL,
	[DomainName] [nvarchar](255) NOT NULL,
	[ForceWWW] [bit] NOT NULL,
	[ForceSSL] [bit] NOT NULL,
 CONSTRAINT [PK_ws_DomainNames] PRIMARY KEY CLUSTERED 
(
	[WebsiteId] ASC,
	[DomainName] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[ws_DomainNames]  WITH CHECK ADD  CONSTRAINT [FK_ws_DomainNames_ws_Websites] FOREIGN KEY([WebsiteId])
REFERENCES [dbo].[ws_Websites] ([WebsiteId])
ON UPDATE CASCADE
ON DELETE CASCADE
GO

ALTER TABLE [dbo].[ws_DomainNames] CHECK CONSTRAINT [FK_ws_DomainNames_ws_Websites]
GO

ALTER TABLE [dbo].[ws_DomainNames] ADD  CONSTRAINT [DF_ws_DomainNames_ForceWWW]  DEFAULT ((0)) FOR [ForceWWW]
GO

ALTER TABLE [dbo].[ws_DomainNames] ADD  CONSTRAINT [DF_ws_DomainNames_ForceSSL]  DEFAULT ((0)) FOR [ForceSSL]
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[ws_Themes](
	[ThemeId] [uniqueidentifier] NOT NULL,
	[ThemeName] [nvarchar](255) NOT NULL,
	[Cost] [decimal](18, 2) NULL,
	[System] [bit] NULL,
 CONSTRAINT [PK_ws_Themes] PRIMARY KEY CLUSTERED 
(
	[ThemeId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[ws_Themes] ADD  CONSTRAINT [DF_Themes_ThemeID]  DEFAULT (newid()) FOR [ThemeId]
GO

CREATE TABLE [dbo].[ws_ThemesPerWebsite](
	[WebsiteId] [uniqueidentifier] NOT NULL,
	[ThemeId] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_ws_ThemesPerWebsite] PRIMARY KEY CLUSTERED 
(
	[WebsiteId] ASC,
	[ThemeId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[ws_ThemesPerWebsite]  WITH CHECK ADD  CONSTRAINT [FK_ws_ThemesPerWebsite_ws_Themes] FOREIGN KEY([ThemeId])
REFERENCES [dbo].[ws_Themes] ([ThemeId])
GO

ALTER TABLE [dbo].[ws_ThemesPerWebsite] CHECK CONSTRAINT [FK_ws_ThemesPerWebsite_ws_Themes]
GO

ALTER TABLE [dbo].[ws_ThemesPerWebsite]  WITH CHECK ADD  CONSTRAINT [FK_ws_ThemesPerWebsite_ws_Websites] FOREIGN KEY([WebsiteId])
REFERENCES [dbo].[ws_Websites] ([WebsiteId])
GO

ALTER TABLE [dbo].[ws_ThemesPerWebsite] CHECK CONSTRAINT [FK_ws_ThemesPerWebsite_ws_Websites]
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[ws_Pages](
	[PageId] [int] IDENTITY(1,1) NOT NULL,
	[WebsiteId] [uniqueidentifier] NOT NULL,
	[PageGuid] [uniqueidentifier] NOT NULL,
	[ParentId] [int] NOT NULL,
	[Title] [nvarchar](250) NOT NULL,
	[MenuTitle] [nvarchar](50) NOT NULL,
	[PageContent] [nvarchar](max) NULL,
	[Keywords] [nvarchar](500) NULL,
	[Description] [nvarchar](500) NULL,
	[SortOrder] [int] NOT NULL,
	[Template] [varchar](50) NOT NULL,
	[CreatedBy] [uniqueidentifier] NOT NULL,
	[CreatedOn] [datetime] NOT NULL,
	[ModifiedBy] [uniqueidentifier] NOT NULL,
	[ModifiedOn] [datetime] NOT NULL,
	[Published] [bit] NOT NULL,
	[PublishDate] [datetime] NOT NULL,
	[Slug] [nvarchar](255) NOT NULL,
 CONSTRAINT [PK_ws_Content_Page_1] PRIMARY KEY CLUSTERED 
(
	[PageId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[ws_Pages]  WITH CHECK ADD  CONSTRAINT [FK_ws_Content_Page_ws_Websites] FOREIGN KEY([WebsiteId])
REFERENCES [dbo].[ws_Websites] ([WebsiteId])
ON UPDATE CASCADE
GO

ALTER TABLE [dbo].[ws_Pages] CHECK CONSTRAINT [FK_ws_Content_Page_ws_Websites]
GO

ALTER TABLE [dbo].[ws_Pages] ADD  CONSTRAINT [DF_ws_Content_Page_ParentId]  DEFAULT ((0)) FOR [ParentId]
GO

ALTER TABLE [dbo].[ws_Pages] ADD  CONSTRAINT [DF_ws_Content_Page_SortOrder]  DEFAULT ((0)) FOR [SortOrder]
GO

ALTER TABLE [dbo].[ws_Pages] ADD  CONSTRAINT [DF_ws_Content_Page_CreatedOn_1]  DEFAULT (getutcdate()) FOR [CreatedOn]
GO

ALTER TABLE [dbo].[ws_Pages] ADD  CONSTRAINT [DF_ws_Content_Page_ModifiedOn_1]  DEFAULT (getutcdate()) FOR [ModifiedOn]
GO

ALTER TABLE [dbo].[ws_Pages] ADD  CONSTRAINT [DF_ws_Content_Pages_Published]  DEFAULT ((0)) FOR [Published]
GO

ALTER TABLE [dbo].[ws_Pages] ADD  CONSTRAINT [DF_ws_Content_Pages_PublishDate]  DEFAULT (getutcdate()) FOR [PublishDate]
GO

PRINT '----------------------------------------'
PRINT 'Completed execution of InstallCore.SQL'
PRINT '----------------------------------------'